package cn.itsource.listener;

import cn.itsource.system.service.IPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;


@WebListener//申明自定义的web监听器，被容器注册和使用
public class PermissionScanInitListener implements ServletContextListener {

    @Autowired
    private IPermissionService permissionService;
    /**
     * 初始化
     * @param sce
     */
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("我自定义的监听器启动了.....");
        //扫描注解  得到sn 和 name   保存数据库
        new Thread(()-> permissionService.init()).start();
    }

    /**
     * 销毁   -- 一般不写代码
     * @param sce
     */
    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        System.out.println("我自定义的监听器销毁了......");
    }
}
